package com.waterworld.watch.mine.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import com.waterworld.watch.R;
import com.waterworld.watch.common.activity.BaseActivity;
import com.waterworld.watch.common.bean.NotificationCategoryBean;
import com.waterworld.watch.common.net.BaseResultBean;
import com.waterworld.watch.common.net.NetManager;
import com.waterworld.watch.common.util.ScreenAdapterUtil;
import com.waterworld.watch.common.util.ToastUtils;
import com.waterworld.watch.mine.adapter.NotificationCategoryAdapter;
import rx.Subscriber;

import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class NotificationCategoryActivity extends BaseActivity {

    @BindView(R.id.header_parent)
    LinearLayout headerParent;

    @BindView(R.id.header_back)
    ImageView headerBack;

    @BindView(R.id.header_title)
    TextView headerTitle;

    @BindView(R.id.rv_notification_category)
    RecyclerView category;

    List<NotificationCategoryBean> mList = new ArrayList<>();
    NotificationCategoryAdapter mAdapter = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notification_classify);
        ButterKnife.bind(this);
        initView();
    }

    private void initView() {
        setViewSize(headerParent, LinearLayout.LayoutParams.MATCH_PARENT, ScreenAdapterUtil.getHeightPx(this)/10);
        headerBack.setVisibility(View.VISIBLE);
        headerTitle.setText(getString(R.string.msg_notice));
        headerTitle.setVisibility(View.VISIBLE);

        //网络请求
        NetManager.getInstance().getMessageGroup(new Subscriber<BaseResultBean<NotificationCategoryBean[]>>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable e) {
                ToastUtils.showShort(NotificationCategoryActivity.this, getString(R.string.data_error));
            }

            @Override
            public void onNext(BaseResultBean<NotificationCategoryBean[]> baseResultBean) {
                //数据处理
                if (baseResultBean.getCode() == 0) {
                    mList.addAll(Arrays.asList(baseResultBean.getData()));
                    mAdapter = new NotificationCategoryAdapter(NotificationCategoryActivity.this,mList);
                    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(NotificationCategoryActivity.this);
                    linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
                    category.setLayoutManager(linearLayoutManager);
                    category.setAdapter(mAdapter);
                }
            }
        });
    }

    @OnClick(R.id.header_back)
    void onBack() {
        finish();
    }
}
